﻿<?php
session_start();
$_SESSION['incorrectCaptcha'] =  0;
$_SESSION['emptyFields'] = isset($_SESSION['emptyFields']) ? $_SESSION['emptyFields'] : 0;
$_SESSION['logged'] = isset($_SESSION['logged']) ? $_SESSION['logged'] : 0;
//$_SESSION['register'] = isset($_SESSION['register']) ? $_SESSION['register'] : 0;


if( isset($_POST['password']) && isset($_POST['username']) && isset($_POST['user_answer']) && isset($_SESSION['adder']) ) {		
		if($_POST['password'] == "" or $_POST['username'] == ""){
			$_SESSION['emptyFileds'] = 1;
			header('Location:register.php');
			die();
		}else{
			if($_POST['user_answer'] == $_SESSION['adder']){
				$servername="localhost";
				$username="root";
				$conn=  mysql_connect($servername,$username)or die(mysql_error());
				mysql_select_db("irgc",$conn);
				$sql="insert into user (username,password,status)values('$_POST[username]','$_POST[password]',1)";
				$result=mysql_query($sql,$conn) or die(mysql_error());	
				$_SESSION['logged'] = 1;
				$_SESSION['username'] = $_POST['username'];
			}else{
				$_SESSION['incorrectCaptcha'] =1;
				header('Location:register.php');
				die();
			}
		}
}else if(isset($_POST['passwordLogin']) && isset($_POST['usernameLogin']) && isset($_POST['user_answerLogin']) && isset($_SESSION['adder'])){
	if($_POST['passwordLogin'] == "" or $_POST['usernameLogin'] == ""){
		$_SESSION['emptyFileds'] = 1;
		header('Location:login.php');
		die();
	}else{
		if($_POST['user_answerLogin'] == $_SESSION['adder']){
			$servername="localhost";
			$username="root";
			$conn= mysql_connect($servername,$username)or die(mysql_error());
			mysql_select_db("irgc",$conn);
			$sql="select * from user where username='$_POST[usernameLogin]' and password='$_POST[passwordLogin]'";
			$result=mysql_query($sql,$conn) or die(mysql_error());
			$number = mysql_num_rows($result);
			if($number !=0){
				$_SESSION['logged'] = 1;
				$_SESSION['username'] = $_POST['usernameLogin'];
				$servername = "localhost";
				$username = "root";
				$conn = mysql_connect($servername,$username)or die(mysql_error());
				mysql_select_db("irgc",$conn);
				$sql="UPDATE  `irgc`.`user` SET  `status` =  '1' WHERE  `user`.`username` ='".$_SESSION['username']."';"; //status is column that indicate OFFline or ONline of an user(0:off ,1:on)
				$result=mysql_query($sql,$conn) or die(mysql_error());	
			}else{
				$_SESSION['incorrectPass'] = 1;
				header('Location:login.php');
				die();				}
		}else{
			$_SESSION['incorrectCaptcha'] =1;
			header('Location:login.php');
			die();
		}
	}
}/*else{
	if(isset($_SESSION['formLogin']) && $_SESSION['formLogin']){
		$_SESSION['emptyFileds'] = 1;
		header('Location:login.php');
		die();
	}else{
		if(isset($_SESSION['formRegister']) && $_SESSION['formRegister']){
		$_SESSION['emptyFileds'] = 1;
		header('Location:register.php');
		die();
		}
	}
}*/


	
?>
﻿<!DOCTYPE HTML>
<html>

<head>
  <title>Iran Game Center </title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <!-- stylesheets -->
  <link href="css/style.css" rel="stylesheet" type="text/css" />
  <link href="css/light.css" rel="stylesheet" type="text/css" />
  <!-- modernizr enables HTML5 elements and feature detects -->
  <script type="text/javascript" src="js/modernizr-1.5.min.js"></script>
</head>

<body>
  <div id="main">
  <?php
    if($_SESSION['logged']){
		echo "<a href=logout.php>خروج</a> &nbsp&nbsp&nbsp".$_SESSION['username']."  سلام";
	}
  ?>
    <!-- begin header -->
    <header>
	<nav>
        <ul class="sf-menu" id="nav">
          <li class="selected"><a href="index.php">خانه</a></li>
		  <?php
			if (!$_SESSION['logged']){//if <<not>> sign in then do following :
		  ?>
			<li><a href="#">ورود/ثبت نام</a>
				<ul>
				<li><a href="login.php">ورود</a></li>
				<li><a href="register.php">ثبت نام</a></li>
				</ul>
			</li>
		  <?php
			}else{
		  ?>
			<li><a href="#">بازی کردن</a>
				<ul>
				<li><a href="play.php?gameType='tictactoe'">  X O بازی</a></li>
				</ul>
			</li>
		  <?php
			}
		  ?>
			

        </ul>
      </nav>
      <div id="logo"><h1>مرکز بازی های <a href="#">آنلاین</a>ایران</h1></div>
    </header>
    <!-- end header -->

    <!-- begin content -->
    <div id="site_content">
      <ul class="slideshow">
        <li class="show"><img width="950" height="450" src="images/home_1.jpg" alt="&quot شما در این سایت میتوانید به بازی بصورت آنلاین بپردازید &quot;" /></li>
        <li><img width="950" height="450" src="images/home_2.jpg" alt="&quot;بازی هایی که جذابیت خاصی دارند و همیشه جذاب بوده اند &quot;" /></li>
        <li><img width="950" height="450" src="images/home_3.jpg" alt="&quot;در بعضی از این بازی ها شانس وجود دارد و در برخی فکر و در برخی دیگر خلاقیت  ....&quot;" /></li>
      </ul>
    </div>
    <!-- end content -->

    <!-- begin footer -->
    <footer>
	  <div id="headermenu">
		<ul>
			<li><a href="#" id="myButton">مشاهده بازی ها </a></li>
		<ul>
	  </div>  
    </footer>
    <!-- end footer -->

  </div>
  <!-- javascript at the bottom for fast page loading -->
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/jquery.easing-sooper.js"></script>
  <script type="text/javascript" src="js/jquery.sooperfish.js"></script>
  <script type="text/javascript" src="js/image_fade.js"></script>
  <!-- initialise sooperfish menu -->
  <script type="text/javascript">
    $(document).ready(function() {
      $('ul.sf-menu').sooperfish();
    });
  </script>
</body>
</html>
